#include <iostream>
using namespace std;
int main() {
    int arr[3][3] = {0};
    int s = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> arr[i][j];
            s += arr[i][j];
        }
    }

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (arr[i][j] == 0)
            {
                arr[i][j] = 45-s;
                break;
            }
        }
    }

    int x, y;
    for (int i = 0; i < 3; i++)
    {
        cin >> x >> y;
        cout << arr[x - 1][y - 1] << endl;
    }
    int n,sum=0;
    cin >> n;
    if (1 <= n &&n<= 3)
    {
        for (int i = 0; i < 3; i++)
        {
            sum += arr[n - 1][i];
        }
    }
    if (4 <= n&&n <= 6)
    {
        for (int i = 0; i < 3; i++)
        {
            sum += arr[i][n - 4];
        }
    }
    if (n == 7)
    {
        for (int i = 0; i < 3; i++)
        {
            sum += arr[i][i];
        }
    }
    if (n == 8)
    {
        for (int i = 0; i < 3; i++)
        {
            sum += arr[2-i][i];
        }
    }
    switch (sum) 
    {
    case 6:
        cout << 10000; break;
    case 7:
        cout << 36; break; 
    case 8:
        cout << 720; break;
    case 9:
        cout << 360; break;
    case 10:
        cout << 80; break;
    case 11:
        cout << 252; break;
    case 12:
        cout << 108; break;
    case 13:
        cout << 72; break;
    case 14:
        cout << 54; break;
    case 15:
        cout << 180; break;
    case 16:
        cout << 72; break;
    case 17:
        cout << 180; break;
    case 18:
        cout << 119; break;
    case 19:
        cout << 36; break;
    case 20:
        cout << 306; break;
    case 21:
        cout << 1080; break;
    case 22:
        cout << 144; break;
    case 23:
        cout << 1800; break;
    case 24:
        cout << 3600; break;
    }

    return 0;
}